package io.yunho.yunho.interview.two.java8.webflux.routerfunction;

import io.yunho.yunho.interview.two.java8.webflux.holedemo.User;
import io.yunho.yunho.interview.two.java8.webflux.holedemo.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

/**
 * @author: yunho
 * @date: 2021/5/13 18:04
 * @description:
 */
@Component
@RequiredArgsConstructor
public class UserHandlerOne implements HandlerFunction<ServerResponse> {

    private final UserRepository userRepository;

    @Override
    public Mono<ServerResponse> handle(ServerRequest serverRequest) {
        return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON)
                .body(this.userRepository.findAll(), User.class);
    }
}
